package com.fr.chicken.controller;

import com.fr.chicken.annotation.Verification;
import com.fr.chicken.facade.base.BaseResponseDTO;
import com.fr.chicken.facade.request.*;
import com.fr.chicken.facade.response.*;
import com.fr.chicken.service.AdminService;
import com.fr.chicken.util.IpUtil;
import com.fr.chicken.util.JwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping(value = "/admin")
@Api(value = "/api-admin", description = "管理员信息")
public class AdminController {
    @Resource
    private AdminService adminService;

    @ApiOperation(value = "后台登录", response = AdminLonginResponseDTO.class, notes = "后台登录")
    @RequestMapping(value = "/login", method = RequestMethod.POST, produces = "application/json")
    public AdminLonginResponseDTO login(@RequestBody @ApiParam(name = "json对象", value = "传入json格式", required = true) AdminLoginRequsetDTO requset,HttpServletRequest httpRequest) {
        requset.setLoginIp(IpUtil.getIpAddr(httpRequest));
        AdminLonginResponseDTO response = this.adminService.login(requset);
        if (response.getIsLogin() == true) {
            String jwt = JwtUtil.generateToken(requset.getAdminname(), requset.getPassword());
            response.setAccessToken(jwt);
        }
        return response;
    }

    @Verification
    @ApiOperation(value = "鸡场配置信息查询", response = GetChickenConfigureResponseDTO.class, notes = "鸡场配置信息查询")
    @RequestMapping(value = "/getChickenConfigure", method = RequestMethod.GET, produces = "application/json")
    public GetChickenConfigureResponseDTO getChickenConfigure(@RequestHeader String accessToken) {
        GetChickenConfigureResponseDTO response = this.adminService.getChickenConfigure();
        return response;
    }

    @Verification
    @ApiOperation(value = "鸡场配置修改", response = BaseResponseDTO.class, notes = "鸡场配置修改")
    @RequestMapping(value = "/updateChickenConfigure", method = RequestMethod.POST, produces = "application/json")
    public BaseResponseDTO updateChickenConfigure(@RequestHeader String accessToken,@RequestBody @ApiParam(name = "json对象", value = "传入json格式", required = true) UpdateChickenConfigureRequsetDTO requsetDTO) {
        BaseResponseDTO response = this.adminService.updateChickenConfigure(requsetDTO);
        return response;
    }

    @Verification
    @ApiOperation(value = "游戏配置修改", response = BaseResponseDTO.class, notes = "游戏配置修改")
    @RequestMapping(value = "/updateMaxConfigure", method = RequestMethod.POST, produces = "application/json")
    public BaseResponseDTO updateMaxConfigure(@RequestHeader String accessToken,@RequestBody @ApiParam(name = "json对象", value = "传入json格式", required = true) UpdateMaxConfigureRequsetDTO requsetDTO) {
        BaseResponseDTO response = this.adminService.updateMaxConfigure(requsetDTO);
        return response;
    }

    @Verification
    @ApiOperation(value = "游戏数据配置信息查询", response = GetMaxConfigureResponseDTO.class, notes = "游戏数据配置信息查询")
    @RequestMapping(value = "/getMaxConfigure", method = RequestMethod.GET, produces = "application/json")
    public GetMaxConfigureResponseDTO getMaxConfigure(@RequestHeader String accessToken) {
        GetMaxConfigureResponseDTO response = this.adminService.getMaxConfigure();
        return response;
    }

    @Verification
    @ApiOperation(value = "兑换配置修改", response = AdminLonginResponseDTO.class, notes = "兑换配置修改")
    @RequestMapping(value = "/updateExchangeConfigure", method = RequestMethod.POST, produces = "application/json")
    public BaseResponseDTO updateExchangeConfigure(@RequestHeader String accessToken,@RequestBody @ApiParam(name = "json对象", value = "传入json格式", required = true) UpdateExchangeConfigureRequsetDTO requsetDTO) {
        BaseResponseDTO response = this.adminService.updateExchangeConfigure(requsetDTO);
        return response;
    }

    @Verification
    @ApiOperation(value = "添加兑换配置", response = BaseResponseDTO.class, notes = "添加兑换配置")
    @RequestMapping(value = "/insertExchangeConfigure", method = RequestMethod.POST, produces = "application/json")
    public BaseResponseDTO insertExchangeConfigure(@RequestHeader String accessToken,@RequestBody @ApiParam(name = "json对象", value = "传入json格式", required = true) InsertExchangeConfigureRequsetDTO requsetDTO) {
        BaseResponseDTO response = this.adminService.insertExchangeConfigure(requsetDTO);
        return response;
    }

    @Verification
    @ApiOperation(value = "删除兑换配置", notes = "删除兑换配置")
    @RequestMapping(value = "/deleteExchangeConfigure/{id}", method = RequestMethod.POST, produces = "application/json")
    public BaseResponseDTO deleteExchangeConfigure(@RequestHeader String accessToken, @PathVariable(value = "id") @ApiParam(required = true, value = "id") Integer id) {
        BaseResponseDTO response = adminService.deleteExchangeConfigure(id);
        return response;
    }

    @Verification
    @ApiOperation(value = "修改管理员密码", notes = "修改管理员密码")
    @RequestMapping(value = "/updateAdminPassword", method = RequestMethod.POST, produces = "application/json")
    public BaseResponseDTO updateAdminPassword(@RequestHeader String accessToken,@RequestBody @ApiParam(name = "json对象", value = "传入json格式", required = true) UpdateAdminPasswordRequsetDTO requsetDTO) {
        BaseResponseDTO response = adminService.updateAdminPassword(requsetDTO);
        return response;
    }

    @Verification
    @ApiOperation(value = "查询平台信息", notes = "查询平台信息")
    @RequestMapping(value = "/getPlatformData", method = RequestMethod.GET, produces = "application/json")
    public GetPlatformDataResponseDTO getPlatformData(@RequestHeader String accessToken) {
        GetPlatformDataResponseDTO response = adminService.getPlatformData();
        return response;
    }

    @Verification
    @ApiOperation(value = "查询管理员登录记录", notes = "查询管理员登录记录")
    @RequestMapping(value = "/getAdminLoginList", method = RequestMethod.GET, produces = "application/json")
    public GetAdminLoginListResponseDTO getAdminLoginList(@RequestHeader String accessToken,GetAdminLoginListRequsetDTO requsetDTO) {
        GetAdminLoginListResponseDTO response = adminService.getAdminLoginList(requsetDTO);
        return response;
    }

    @Verification
    @ApiOperation(value = "更新玩家数据", notes = "更新玩家数据")
    @RequestMapping(value = "/updateUserNums", method = RequestMethod.POST, produces = "application/json")
    public BaseResponseDTO updateUserNums(@RequestHeader String accessToken,@RequestBody @ApiParam(name = "json对象", value = "传入json格式", required = true) UpdateUserNumsRequsetDTO requsetDTO,HttpServletRequest httpRequest) {
        requsetDTO.setLoginIp(IpUtil.getIpAddr(httpRequest));
        BaseResponseDTO response = adminService.updateUserNums(requsetDTO);
        return response;
    }

    @Verification
    @ApiOperation(value = "查询总代理下的一级代理", notes = "查询总代理下的一级代理")
    @RequestMapping(value = "/getOneAgentInfoList", method = RequestMethod.GET, produces = "application/json")
    public GetPlayerInfoListResponseDTO getOneAgentInfoList(@RequestHeader String accessToken, GetOneAgentInfoListRequsetDTO requsetDTO) {
        GetPlayerInfoListResponseDTO response = adminService.getOneAgentInfoList(requsetDTO);
        return response;
    }

    @Verification
    @ApiOperation(value = "vip配置", notes = "vip配置")
    @RequestMapping(value = "/getVipConfigure", method = RequestMethod.GET, produces = "application/json")
    public GetVipConfigureResponseDTO getVipConfigure(@RequestHeader String accessToken) {
        GetVipConfigureResponseDTO response = adminService.getVipConfigure();
        return response;
    }

    @Verification
    @ApiOperation(value = "更新vip数据", notes = "更新vip数据")
    @RequestMapping(value = "/updateVipConfigure", method = RequestMethod.POST, produces = "application/json")
    public BaseResponseDTO updateVipConfigure(@RequestHeader String accessToken,@RequestBody @ApiParam(name = "json对象", value = "传入json格式", required = true) UpdateVipConfigureRequsetDTO requsetDTO,HttpServletRequest httpRequest) {
        BaseResponseDTO response = adminService.updateVipConfigure(requsetDTO);
        return response;
    }

    @Verification
    @ApiOperation(value = "获取激活码信息", notes = "获取激活码信息")
    @RequestMapping(value = "/getActivationCodeInfo", method = RequestMethod.GET, produces = "application/json")
    public GetActivationCodeInfoResponseDTO getActivationCodeInfo(@RequestHeader String accessToken) {
        GetActivationCodeInfoResponseDTO response = adminService.getActivationCodeInfo();
        return response;
    }

    @Verification
    @ApiOperation(value = "更新商品数据", notes = "更新商品数据")
    @RequestMapping(value = "/updateGoods", method = RequestMethod.POST, produces = "application/json")
    public BaseResponseDTO updateGoods(@RequestHeader String accessToken,@RequestBody @ApiParam(name = "json对象", value = "传入json格式", required = true) UpdateGoodsRequsetDTO requsetDTO,HttpServletRequest httpRequest) {
        BaseResponseDTO response = adminService.updateGoods(requsetDTO);
        return response;
    }
}
